package com.alm.token.ui.data;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lidengzhou on 17/6/26.
 */

public class Options {

    /**
     * offset=默认0 [可空]
     * */
    private int offset;

    /**
     * limit=分页大小,默认10
     * */
    private int limit = 10;

    /**
     * order="desc" [不可变]
     * */
    private String order = "desc";

    /**
     * sortby="creation_time"
     */
    private String sortBy = "creation_time";

    /**
     * page，默认为－1，不为－1的时候，会覆盖掉上面的offset
     * 通过page转化成offset
     * */
    private int page = -1;

    public void setOrder(String order) {
        this.order = order;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public String getOrder() {
        return order;
    }

    public String getSortBy() {
        return sortBy;
    }

    public void setSortBy(String sortBy) {
        this.sortBy = sortBy;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public Map<String, String> getOptions() {
        Map<String, String> map = new HashMap<>();
        if (this.page != -1) {
            int offset = this.limit * page;
            map.put("offset", String.valueOf(offset));
        } else {
            map.put("offset", String.valueOf(offset));
        }
        map.put("limit", String.valueOf(limit));
        map.put("order", this.order);
        map.put("sortby", this.sortBy);
        return map;
    }


}
